package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.qiaoyanqing.ximalaya.discovermodule.discover_activity.DiscoverRecomentAlbumActivity;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.DiscoverRecommendHotRecommend;
import com.qiaoyanqing.ximalaya.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/3.
 */

public class Discover_Recommend_ListviewAdapter extends BaseAdapter {

    private List<DiscoverRecommendHotRecommend.HotRecommendsBean.ListBean>mData;
    private Context mContext;



    public Discover_Recommend_ListviewAdapter(List<DiscoverRecommendHotRecommend.HotRecommendsBean.ListBean> data, Context context) {
        mData = data;
        mContext = context;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getViewTypeCount() {
        return super.getViewTypeCount();
    }

    @Override
    public int getCount() {
        //   MyLog.i("flag","------mHealthsData"+mHealthsData.size());
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder1 holder1=null;

        if (convertView == null) {
            holder1=new ViewHolder1();
            convertView= LayoutInflater.from(mContext).inflate(R.layout.reco_health,parent,false);
            holder1.title= (TextView) convertView.findViewById(R.id.header_title);
            holder1.text[0]= (TextView) convertView.findViewById(R.id.first_text);
            holder1.text[1]= (TextView) convertView.findViewById(R.id.mid_text);
            holder1.text[2]= (TextView) convertView.findViewById(R.id.third_text);
            holder1.textin[0]= (TextView) convertView.findViewById(R.id.inTitle_first);
            holder1.textin[1]= (TextView) convertView.findViewById(R.id.inTitle_mid);
            holder1.textin[2]= (TextView) convertView.findViewById(R.id.inTitle_third);
            holder1.img[0]= (ImageView) convertView.findViewById(R.id.first_image);
            holder1.img[1]= (ImageView) convertView.findViewById(R.id.mid_image);
            holder1.img[2]= (ImageView) convertView.findViewById(R.id.third_image);
         //   holder1.lalalala= (RelativeLayout) convertView.findViewById(R.id.lalalala);
            convertView.setTag(holder1);

        }else {
            holder1= (ViewHolder1) convertView.getTag();
        }
        //各种听
        //赋值
        holder1.title.setText(mData.get(position).getTitle());
        holder1.text[0].setText(mData.get(position).getList().get(0).getTitle());
        holder1.text[1].setText(mData.get(position).getList().get(1).getTitle());
        holder1.text[2].setText(mData.get(position).getList().get(2).getTitle());
        holder1.textin[0].setText(mData.get(position).getList().get(0).getTrackTitle());
        holder1.textin[1].setText(mData.get(position).getList().get(1).getTrackTitle());
        holder1.textin[2].setText(mData.get(position).getList().get(2).getTrackTitle());
        String icPath0=mData.get(position).getList().get(0).getCoverSmall();
        String icPath1=mData.get(position).getList().get(1).getCoverSmall();
        String icPath2=mData.get(position).getList().get(2).getCoverSmall();
        Picasso.with(mContext).load(icPath0).into(holder1.img[0]);
        Picasso.with(mContext).load(icPath1).into(holder1.img[1]);
        Picasso.with(mContext).load(icPath2).into(holder1.img[2]);

        holder1.img[0].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, DiscoverRecomentAlbumActivity.class);
                intent.putExtra("iconpath",mData.get(position).getList().get(0).getCoverSmall());
                intent.putExtra("nickname",mData.get(position).getList().get(0).getNickname());
                intent.putExtra("title",mData.get(position).getList().get(0).getTitle());
                intent.putExtra("album",mData.get(position).getList().get(0).getAlbumId());
                intent.putExtra("playcounts",mData.get(position).getList().get(0).getPlaysCounts());
                mContext.startActivity(intent);

            }
        });
        holder1.img[1].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, DiscoverRecomentAlbumActivity.class);
                intent.putExtra("iconpath",mData.get(position).getList().get(1).getCoverSmall());
                intent.putExtra("nickname",mData.get(position).getList().get(1).getNickname());
                intent.putExtra("title",mData.get(position).getList().get(1).getTitle());
                intent.putExtra("album",mData.get(position).getList().get(1).getAlbumId());
                intent.putExtra("playcounts",mData.get(position).getList().get(1).getPlaysCounts());
                mContext.startActivity(intent);
            }
        });
        holder1.img[2].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, DiscoverRecomentAlbumActivity.class);
                intent.putExtra("iconpath",mData.get(position).getList().get(2).getCoverSmall());
                intent.putExtra("nickname",mData.get(position).getList().get(2).getNickname());
                intent.putExtra("title",mData.get(position).getList().get(2).getTitle());
                intent.putExtra("album",mData.get(position).getList().get(2).getAlbumId());
                intent.putExtra("playcounts",mData.get(position).getList().get(2).getPlaysCounts());
                mContext.startActivity(intent);
            }
        });




        return convertView;

    }


    private static class ViewHolder1{
        private TextView title;
        private TextView[] text=new TextView[3];
        private ImageView[] img=new ImageView[3];
        private TextView[] textin=new TextView[3];
        private RelativeLayout lalalala;
    }




}
